<?php
namespace App\Common\Lib\Err;

use App\Common as com;
use App\Common\Lib\Err\Exception as nameException;
use App\Common\Lib\Err as nameErr;
use function PHPUnit\Framework\throwException;

class Exception extends nameErr\BaseException\Throw_ {


	
	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param \Throwable $e
	 * @return string
	 */
	public static function getSimpleShowExceptionInfo( \Throwable $e ):string {
		$echoStr = "\n【simpleShowExceptionInfo】\n";
		$echoStr .= '[throw exception] ' . get_class( $e ) . "\n";
		$echoStr .= '[code] ' . $e->getCode() . "\n";
		$echoStr .= '[message] ' . $e->getMessage() . "\n";
		$echoStr .= '[file] ' . $e->getFile() . "\n";
		$echoStr .= '[line] ' . $e->getLine() . "\n";
		// $echoStr .= "The error: " . $e->getFile() . "(" . $e->getLine() . ")" . "\n";
		$echoStr .= "[stack trace]：\n";
		$i = 0;
		foreach ( $e->getTrace() as $traceValue ){
			$i++;
			//
			if( isset( $traceValue['file'] ) ){
				$echoStr .= "#{$i} {$traceValue['file']}({$traceValue['line']})\n";
			}else{
				$echoStr .= "#{$i} 未知数据\n";
			}
		}
		//
		return $echoStr;
	}

	/**
	 * @param \Throwable $e
	 * @return void
	 */
	public static function showSimpleShowExceptionInfo( \Throwable $e ) {
		d( self::getSimpleShowExceptionInfo( $e ) );
	}

	public static function getSimpleDebugBacktrace( int $limitNum ):array {
		$debugBacktrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $limitNum );
		$currentCourseData = [];
		foreach( $debugBacktrace as $debugBacktraceValue ){
			$currentCourseData[] = "{$debugBacktraceValue['file']}[{$debugBacktraceValue['line']}]";
		}
		//
		return $currentCourseData;
	}

}
